package xyz.ddlnt.user.usr.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.commonutil.util.HttpUtils;
import xyz.ddlnt.model.dto.PageDTO;
import xyz.ddlnt.model.dto.PostDescriptionDTO;
import xyz.ddlnt.model.dto.SearchDTO;
import xyz.ddlnt.model.vo.PostLatestVO;
import xyz.ddlnt.model.vo.PostNodeVO;
import xyz.ddlnt.model.vo.PostVO;
import xyz.ddlnt.serviceusrclient.client.PostFeignClient;

import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/9 19:55
 */
@Slf4j
@Tag(name = "帖子接口测试")
@RequestMapping("/post")
@RestController
public class PostController {
    @Resource
    private PostFeignClient postFeignClient;

    @Operation(summary = "发布帖子")
    @PostMapping("/PublishPost")
    Result<Boolean> PublishPost(@RequestBody PostDescriptionDTO postDescriptionDTO) {
        return postFeignClient.PublishPost(postDescriptionDTO);
    }

    @Operation(summary = "获取帖子列表")
    @PostMapping("/getPostLists")
    Result<List<PostVO>> getPostLists(@RequestBody PageDTO pageDTO) {
        return postFeignClient.getPostLists(pageDTO);
    }

    @Operation(summary = "搜索帖子")
    @PostMapping("/searchPost")
    Result<List<PostVO>> searchPostList(@RequestBody SearchDTO searchDTO) {
        return postFeignClient.searchPostList(searchDTO);
    }

    @Operation(summary = "获取帖子信息")
    @GetMapping("/getPost/{postId}")
    public Result<PostVO> getPost(@PathVariable Long postId) {
        return postFeignClient.getPost(postId);
    }

    @Operation(summary = "查询博主最新发布列表")
    @PostMapping("/getBloggerPublish")
    Result<List<PostVO>> getBloggerPublish(@RequestBody PageDTO pageDTO, HttpServletRequest request) {
        if (pageDTO.getId() == 0) {
            pageDTO.setId(HttpUtils.getId(request));
        }
        return postFeignClient.getBloggerPublish(pageDTO);
    }

    @Operation(summary = "查询博主帖子最新发布列表")
    @GetMapping("/getPostLatestList/{bloggerId}")
    public Result<List<PostLatestVO>> getPostLatestList(@PathVariable Long bloggerId) {
        return postFeignClient.getPostLatestList(bloggerId);
    }

    @Operation(summary = "查询帖子目录和节点信息")
    @GetMapping("/getPostNodeInfo/{postId}")
    public Result<PostNodeVO> getPostNodeInfo(@PathVariable Long postId, HttpServletRequest request) {
        Result<PostNodeVO> postNodeInfo = postFeignClient.getPostNodeInfo(postId);
        PostNodeVO data = postNodeInfo.getData();
        data.setId(HttpUtils.getId(request));
        postNodeInfo.setData(data);
        return postNodeInfo;
    }
}
